﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">ModelBase</title>
  <keywords>
    <keyword translate="true">Data</keyword>
    <keyword translate="true">Data handling</keyword>
    <keyword translate="true">DataObjectBase</keyword>
    <keyword translate="true">INotifyPropertyChanged</keyword>
    <keyword translate="true">INotifyPropertyChanging</keyword>
    <keyword translate="true">ModelBase</keyword>
    <keyword translate="true">ObservableObject</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">ModelBase</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" translate="true">ModelBase</link><text styleclass="Normal" translate="true"> (previously known as the </text><text styleclass="Normal" style="font-style:italic;" translate="true">DataObjectBase</text><text styleclass="Normal" translate="true">) class is a generic base class that can be used for all your data classes.</text></para>
    <list id="2" type="ul" listtype="bullet" formatstring="&#183;" format-charset="SYMBOL_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal" style="font-family:Symbol; font-size:10pt; color:#000000;">
      <li styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">Fully serializable</text><text styleclass="Normal" translate="true"> - It is now really easy to store objects on disk or serialize them into memory, either binary or in XML. The data object supports this out of the box, and automatically handles the (de)serialization.</text></li>
      <li styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">Support property changed notifications</text><text styleclass="Normal" translate="true"> - The class supports the </text><text styleclass="Normal" style="font-style:italic;" translate="true">INotifyPropertyChanging</text><text styleclass="Normal" translate="true"> and </text><text styleclass="Normal" style="font-style:italic;" translate="true">INotifyPropertyChanged </text><text styleclass="Normal" translate="true">interfaces so this class can easily be used in WPF, Silverlight and applications to reflect changes to the user.</text></li>
      <li styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">Backwards compatibility</text><text styleclass="Normal" translate="true"> - When serializing your objects to binary, it is hard to maintain the right versions. When you add a new property to a binary class, or change a namespace, the object cannot be loaded any longer. The data object base takes care of this issue and supports backwards compatibility.</text></li>
      <li styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">Validation</text><text styleclass="Normal" translate="true"> - The class implements the IDataErrorInfo interface so it is possible to validate the data object and check the errors. This way, no custom validation code needs to be written outside the data class.</text></li>
      <li styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">Backup &amp; revert</text><text styleclass="Normal" translate="true"> - The class implements the IEditableObject interface which makes it possible to create a state of the object. Then all properties can be edited, and finally, the changes can be applied or cancelled.</text></li>
    </list>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Using the class</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Using the class is extremely simple. Just declare a new class that derives from </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" translate="true">ModelBase</link><text styleclass="Normal" translate="true"> and you are ready to go:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// MyObject class which fully supports serialization,</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// property changed notifications, backwards compatibility and error checking.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;/summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">#if !SILVERLIGHT</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">[Serializable]</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">#endif</text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">class</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> MyObject : ModelBase&lt;MyObject&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> &#160; &#160;</text><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> &#160; &#160;</text><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// Initializes a new object from scratch.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> &#160; &#160;</text><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;/summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> &#160; &#160;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> MyObject() { }</text><br/><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">#if !SILVERLIGHT </text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// Initializes a new object based on &lt;see cref=&quot;SerializationInfo&quot;/&gt;.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;/summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;param name=&quot;info&quot;&gt;&lt;see cref=&quot;SerializationInfo&quot;/&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">// &#160; &#160; that contains the information.&lt;/param&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;param name=&quot;context&quot;&gt;&lt;see cref=&quot;StreamingContext&quot;/&gt;.&lt;/param&gt;</text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">protected</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> MyObject(SerializationInfo info, StreamingContext context)</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> &#160; &#160;: </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">base</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">(info, context) { }</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">#endif</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">As you can see in the code above, the </text><text styleclass="Normal" style="font-style:italic;" translate="true">MyObject</text><text styleclass="Normal" translate="true"> class derives from </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" translate="true">ModelBase</link><text styleclass="Normal" translate="true"> and provides an empty constructor, but also a constructor that is used for binary deserialization. The code above might look complex, but it is created using the </text><text styleclass="Normal" style="font-style:italic;" translate="true">model</text><text styleclass="Normal" translate="true"> code snippet, and you only have to type the name of the class.</text></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Defining properties</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Defining properties for the class is very easy, and works the same like dependency properties. The advantages of this way of defining properties are:</text></para>
    <list id="3" type="ul" listtype="bullet" formatstring="&#183;" format-charset="SYMBOL_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal (list)" style="font-family:Symbol; font-size:10pt; color:#000000;">
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Properties defined like this are automatically included during serialization; no need to specify complex data contracts;</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">You can specify a default value for a property which will be used when the class is constructed or the property is not found during deserialization (in case this property is added to an existing class);</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_PropertyData" styleclass="Normal (list)" translate="true">PropertyData</link><text styleclass="Normal (list)" translate="true"> object can be used to retrieve property values so the compiler checks for errors;</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">You can directly subscribe to change notifications, and all properties automatically support INotifyPropertyChanged out of the box.</text></li>
    </list>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Below is the code that defines a new property </text><text styleclass="Normal" style="font-style:italic;" translate="true">Name</text><text styleclass="Normal" translate="true"> of type string:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// Gets or sets the name.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;/summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> Name</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">{</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> &#160; &#160;get { </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">return</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> GetValue&lt;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&gt;(NameProperty); }</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> &#160; &#160;set { SetValue(NameProperty, value); }</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">}</text><br/><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// Register the Name property so it is known in the class.</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:italic; color:#800000;" translate="true">/// &lt;/summary&gt;</text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">static</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">readonly</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> PropertyData NameProperty = RegisterProperty(&quot;Name&quot;, </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">typeof</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">(</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">), </text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">string</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">.Empty);</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">A registered property can be excluded from serialization if wanted. When the object is deserialized, the default value will be used for the property in that case.</text></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Default values for reference types</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">In lots of cases, a default value for reference types is required in the property definitions. However, and you might have noticed this behavior in for example dependency properties, using an instance as default value can result in unexpected behavior.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Below is an example of a &quot;regular&quot; property registration using a default value for a collection property:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">static</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">readonly</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">PropertyData</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">NameProperty</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">RegisterProperty(&quot;PersonCollection&quot;,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">typeof</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">(Collection&lt;Person&gt;), new Collection&lt;Person&gt;());</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">However, instead of creating a new collection for each new object with this property, only one collection will be created that will be used by all classes that have this property registered. One solution is to pass </text><text styleclass="Normal" style="font-style:italic;" translate="true">null</text><text styleclass="Normal" style="font-style:normal;" translate="true"> as default value and create the collection in the constructor. A better solution is to use the override of </text><link displaytype="text" defaultstyle="true" type="topiclink" href="M_Catel_Data_DataObjectBase_RegisterProperty_5_5f5777d8" styleclass="Normal" style="font-style:normal;" translate="true">RegisterProperty</link><text styleclass="Normal" style="font-style:normal;" translate="true"> with the callback parameters:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">public</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">static</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">readonly</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">PropertyData</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">NameProperty</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">RegisterProperty(&quot;PersonCollection&quot;,</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">typeof</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">(Collection&lt;Person&gt;), () =&gt; new Collection&lt;Person&gt;());</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">This way, every time a new value is needed, the callback will be invoked to create the default value and you will have a true default value for reference types.</text></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Serialization</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">I have mentioned serialization a few times already. Let’s take a look at how easy it is to (de)serialize your objects no matter what assembly version you use. First of all, instead of deriving from </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" translate="true">ModelBase</link><text styleclass="Normal" translate="true">, it is very important to derive from </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_SavableModelBase" styleclass="Normal" translate="true">SavableModelBase</link><text styleclass="Normal" translate="true">.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Depending on the target framework, several options are available as serialization modes:</text></para>
    <para styleclass="Normal"><table styleclass="Default" rowcount="4" colcount="4">
      <tr style="vertical-align:top">
        <td style="width:235px;">
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">Serialization mode</text></para>
        </td>
        <td style="width:100px;">
          <para styleclass="Normal (list)" style="text-align:center;"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">WPF</text></para>
        </td>
        <td style="width:100px;">
          <para styleclass="Normal (list)" style="text-align:center;"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">Silverlight</text></para>
        </td>
        <td style="width:100px;">
          <para styleclass="Normal (list)" style="text-align:center;"><text styleclass="Normal (list)" style="font-weight:bold;" translate="true">WP7</text></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td>
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">Binary</text></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="supported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="notsupported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="notsupported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td>
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">XML</text></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="supported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="supported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="supported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
      </tr>
      <tr style="vertical-align:top">
        <td>
          <para styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">DataContract</text></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="supported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="supported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
        <td>
          <para styleclass="Normal (list)" style="text-align:center;"><image src="supported.png" scale="100.00%" styleclass="Normal (list)"></image></para>
        </td>
      </tr>
    </table></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The code below shows how to save an object (which can, of course, be a complex graph of nested objects):</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">var</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">myObject</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000000;" translate="true">new</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">MyObject();</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">myObject.Save(@&quot;C:\myobject.dob&quot;);</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Looks too easy, but this really is the only thing you need to do. You can specify the serialization mode in the several available overloads of the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="M_Catel_Data_SavableDataObjectBase`1_Save_1_6c2dff68" styleclass="Normal" translate="true">Save</link><text styleclass="Normal" translate="true"> method.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Loading is as easy as saving, as you can see in the following code:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">var</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">myObject</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">=</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#ffffff;" translate="true">&#32;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">MyObject.Load(@&quot;C:\myobject.dob&quot;);</text></para>
    <para styleclass="Heading2"><text styleclass="Heading2" translate="true">Functionality provided out of the box</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" translate="true">ModelBase</link><text styleclass="Normal" translate="true"> provides a lot of functionality out of the box. A few points I want to mention are:</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">INotifyPropertyChanged</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">All properties registered using the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="M_Catel_Data_DataObjectBase_RegisterProperty_5_5f5777d8" styleclass="Normal" translate="true">RegisterProperty</link><text styleclass="Normal" translate="true"> method automatically take care of change notifications.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">IDataErrorInfo</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">It is very easy to set field and business errors using the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="M_Catel_Data_DataObjectBase_SetFieldError_3_8b838e92" styleclass="Normal" translate="true">SetFieldError</link><text styleclass="Normal" translate="true"> and </text><link displaytype="text" defaultstyle="true" type="topiclink" href="M_Catel_Data_DataObjectBase_SetBusinessRuleError_2_8f98a8ad" styleclass="Normal" translate="true">SetBusinessError</link><text styleclass="Normal" translate="true"> methods that can be used in the overridable </text><link displaytype="text" defaultstyle="true" type="topiclink" href="M_Catel_Data_DataObjectBase_ValidateFields" styleclass="Normal" translate="true">ValidateFields</link><text styleclass="Normal" translate="true"> and </text><link displaytype="text" defaultstyle="true" type="topiclink" href="M_Catel_Data_DataObjectBase_ValidateBusinessRules" styleclass="Normal" translate="true">ValidateBusinessRules</link><text styleclass="Normal" translate="true"> methods.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">IEditableObject</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The data object can automatically create an internal backup and restore it, if required, using the </text><text styleclass="Normal" style="font-style:italic;" translate="true">IEditableObject</text><text styleclass="Normal" translate="true"> interface.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" style="font-weight:bold;" translate="true">Serialization</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">As told many times before, using the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_SavableModelBase" styleclass="Normal" translate="true">SavableModelBase</link><text styleclass="Normal" translate="true">, you can simply save your file to a stream (file on disk, stream in memory, etc.).</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Keep in mind that this class is not suitable for database communication, there are much better ways to handle this (ORM mappers such as Entity Framework, NHibernate, LLBLGen Pro, etc.).</text></para>
  </body>
</topic>
